home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / TurboTCP 2.0.1 / MiniTelnet source / CTelnetSettingsDLOG.cp < prev    next >
Encoding:
Text File  |  1994-05-24  |  8.7 KB  |  246 lines  |  [TEXT/MPCC]

  1. /*
  2. ** CTelnetSettingsDLOG.cp
  3. **
  4. **    MiniTelnet application
  5. **    Telnet settings dialog director
  6. **
  7. **    Copyright © 1993-94, FrostByte Design / Eric Scouten
  8. **
  9. */
  10.  
  11.  
  12. #include "CTelnetSettingsDLOG.h"
  13.  
  14. #include "CApplication.h"
  15. #include "CBartender.h"
  16. #include "CDialog.h"
  17. #include "CButton.h"
  18. #include "CCheckBox.h"
  19. #include "CDataFile.h"
  20. #include "CEditText.h"
  21. #include "CPaneBorder.h"
  22. #include "CRadioGroupPane.h"
  23. #include "Commands.h"
  24. #include "TBUtilities.h"
  25. #include "TCLUtilities.h"
  26.  
  27. #include "CMiniTelnetApp.h"
  28. #________________________________________________
  29. **
  30. ** PutSettings
  31. **
  32. **    Copy the settings from the settings record to the dialog box fields.
  33. **
  34. */
  35.  
  36. void CTelnetSettingsDLOG::PutSettings()
  37.  
  38. {
  39.     CCheckBox*        theCheckBox;
  40.     CEditText*        theText;
  41.     CPane*            thePane;
  42.     CRadioGroupPane*    theRadios;
  43.     CView*            theView;
  44.  
  45.  
  46.     // get host name
  47.  
  48.     theView = itsWindow->FindViewByID(itemHostName);
  49.     theText = TCL_DYNAMIC_CAST(CEditText, theView);
  50.     if (theText)
  51.         theText->SetTextPtr((char*) &r.hostName, cstrlen(r.hostName));
  52.  
  53.  
  54.     // get backspace/del configuration
  55.  
  56.     theView = itsWindow->FindViewByID(itemBSPane);
  57.     theRadios = TCL_DYNAMIC_CAST(CRadioGroupPane, theView);
  58.     if (theRadios)
  59.         theRadios->SetStationID((r.backspaceChar == charDEL) ? itemBS_DEL : itemBS_BS);
  60.  
  61.  
  62.     // get window go away config
  63.  
  64.     theView = itsWindow->FindViewByID(itemGoAway);
  65.     theCheckBox = TCL_DYNAMIC_CAST(CCheckBox, theView);
  66.     if (theCheckBox)
  67.         theCheckBox->SetValue(r.closeOnSessionEnd);
  68.  
  69.  
  70.     // get show debug codes config
  71.  
  72.     theView = itsWindow->FindViewByID(itemShowDebug);
  73.     theCheckBox = TCL_DYNAMIC_CAST(CCheckBox, theView);
  74.     if (theCheckBox)
  75.         theCheckBox->SetValue(r.showDebug);
  76.  
  77.  
  78.     // ignore other parms
  79.  
  80.     // force redraw
  81.  
  82.     thePane = TCL_DYNAMIC_CAST(CPane, itsWindow);
  83.     if (thePane)
  84.         thePane->Refresh();
  85.  
  86. }
  87.  
  88.  
  89. //    —— dialog handling functions ——
  90.  
  91. /*______________________________________________________________________
  92. **
  93. ** DoCommand
  94. **
  95. **    Handle all commands that the dialog can understand.
  96. **
  97. **        theCommand (long):    the command number which was issued
  98. **
  99. */
  100.  
  101. void CTelnetSettingsDLOG::DoCommand(long theCommand)
  102.  
  103. {
  104.     CButton*            cancelBtn;
  105.     TelnetSettingsRec    rTemp;
  106.  
  107.  
  108.     // what command did we get?
  109.  
  110.     switch (theCommand) {
  111.  
  112.  
  113.         // OK, Cancel buttons: respond
  114.  
  115.         case cmdOK:
  116.             if (EndDialog(cmdOK, TRUE)) {
  117.                 GrabSettings();
  118.                 BlockMove(&r, &rTemp, sizeof(TelnetSettingsRec));
  119.                 if (TCL_DYNAMIC_CAST(CMiniTelnetApp, gApplication))
  120.                     ((CMiniTelnetApp*) gApplication)->NewSession(&rTemp);
  121.             }
  122.             break;
  123.             
  124.         case cmdCancel:
  125.             EndDialog(cmdCancel, FALSE);
  126.             break;
  127.  
  128.  
  129.         // Save Settings: do it
  130.  
  131.         case cmdSave:
  132.         case cmdSaveAs:
  133.         case cmdSaveSettings:
  134.             GrabSettings();
  135.             DoSaveFile();
  136.             break;
  137.  
  138.  
  139.         // File->Close: cancel out of here
  140.  
  141.         case cmdClose:        
  142.             cancelBtn = ((CDialog*) itsWindow)->FindButton(cmdCancel);
  143.             if (cancelBtn)
  144.                 cancelBtn->SimulateClick();
  145.             EndDialog(cmdCancel, FALSE);
  146.             break;
  147.  
  148.  
  149.         // not ours, send along the chain
  150.  
  151.         default:
  152.             CDialogDirector::DoCommand(theCommand);
  153.     }
  154.  
  155.  
  156.     // if closing window, use a disposer chore
  157.  
  158.     if ((dismissCmd != cmdNull) && (theCommand != cmdClose))
  159.         delete this;
  160.  
  161. }
  162.  
  163.  
  164. /*______________________________________________________________________
  165. **
  166. ** UpdateMenus
  167. **
  168. **    Enable Telnet-specific commands.
  169. **
  170. */
  171.  
  172. void CTelnetSettingsDLOG::UpdateMenus()
  173.  
  174. {
  175.     CDLOGDirector::UpdateMenus();
  176.     gBartender->EnableCmd(cmdSave);
  177.     gBartender->EnableCmd(cmdSaveAs);
  178. }
  179.  
  180.  
  181. //    —— file interactions ——
  182.  
  183. /*______________________________________________________________________
  184. **
  185. ** DoSaveFile
  186. **
  187. **    Save a settings record to a file.
  188. **
  189. */
  190.  
  191. void CTelnetSettingsDLOG::DoSaveFile()
  192.  
  193. {
  194.     Point            corner;                // top left corner of dialog box
  195.     Str255        origName;                // default name for file
  196.     short        nameLength;            // length of default name
  197.     StringHandle    prompt;                // prompt string
  198.     Boolean        wasLocked;
  199.     
  200.     CDataFile*    itsFile;                // don’t keep the file around
  201.     SFReply        macSFReply;            // reply from Std File
  202.  
  203.  
  204.     // ask user for settings file name
  205.  
  206.     FindDlogPosition('DLOG', putDlgID, &corner);
  207.     BlockMove(&r.hostName, &origName[1], 31);
  208.     nameLength = cstrlen(r.hostName);
  209.     origName[0] = (nameLength > 31 ? 31 : nameLength);
  210.     
  211.     prompt = GetString(STR_SettingsPrompt);
  212.     FailNILRes(prompt);
  213.     
  214.     MoveHHi((Handle) prompt);
  215.     HLock((Handle) prompt);
  216.     SFPPutFile(corner, *prompt, origName, NULL, &macSFReply, putDlgID, NULL);
  217.     ReleaseResource((Handle) prompt);
  218.  
  219.  
  220.     // create the file
  221.  
  222.     TRY {
  223.         itsFile = new CDataFile;
  224.         itsFile->SFSpecify(&macSFReply);
  225.  
  226.         if (itsFile->ExistsOnDisk()) {
  227.             itsFile->Open(fsRdWrPerm);
  228.             itsFile->SetLength(0);
  229.                 // TEMPORARY: need to reset file type
  230.         }
  231.         else {
  232.             itsFile->CreateNew(gSignature, kSettingsFileType);
  233.             itsFile->Open(fsRdWrPerm);
  234.         }
  235.         itsFile->WriteSome((Ptr) &r, sizeof(TelnetSettingsRec));
  236.         itsFile->Close();
  237.         delete itsFile;
  238.     }
  239.     
  240.     CATCH {
  241.         ForgetObject(itsFile);
  242.     }
  243.     ENDTRY;
  244.  
  245. }
  246.